<template>
  <div>

    <!--卡片视图-->
    <el-card class="box-card">
      <el-form :model="searchForm" class="demo-form-inline" >
        <el-row :gutter="20">
          <el-form-item>
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="searchForm.starttime" ></el-date-picker>-
              <el-date-picker type="date" placeholder="选择日期" v-model="searchForm.endtime" ></el-date-picker>
            </el-col>
            <el-button @click="searchList" plain type="primary">搜索</el-button>
          </el-form-item>
        </el-row>
      </el-form>

      <el-table
        :data="OrderList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="code"
          label="订单编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="gid"
          label="商品名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="num"
          label="购买数量">
        </el-table-column>
        <el-table-column
          label="订单金额">
          <template slot-scope="scope">
            {{scope.row.oprice}}
          </template>
        </el-table-column>
        <el-table-column
          label="购买用户">
          <template slot-scope="scope">
            {{scope.row.uid | unameFit}}
          </template>
        </el-table-column>

        <el-table-column
          label="下单时间"
          prop="hiredate">
          <template slot-scope="scope">
            {{scope.row.otime | dateFit('YYYY/MM/DD')}}
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          prop="hiredate">
          <template slot-scope="scope">
            {{scope.row.state | staFit}}
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="payMoney(scope.row)" size="small" type="text" v-if="scope.row.state==0" >付款
            </el-button>

          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="page.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>


    </el-card>
  </div>
</template>

<script>
    export default {
        name: "OrderList",
      data(){
        return{

          searchForm:{},
          OrderList:[],
          GoodsList:[],
          userList:[],
          page:{
            pagenum:0,
            pagesize:5
          },
          total:0
        }
      },
      methods:{
        searchList:function () {
          var uid=JSON.parse(sessionStorage.getItem("user")).id;
          this.$http.post("order/list/"+this.page.pagenum+"/"+this.page.pagesize+"/"+uid,this.searchForm).then((res)=>{
            this.OrderList=res.data.result.list;
            this.total=res.data.result.total;
          })
        },
        handleCurrentChange:function(val){

          this.page.pagenum=val;
          this.searchList();
        },
        handleSizeChange:function (val) {
          this.page.pagesize=val;
          this.searchList();
        },
        searchUser:function () {
          this.$http.get("/user/getname").then((res)=>{
            debugger;
            this.userList=res.data.result;
          })
        },
        payMoney:function (row) {
            this.$http.post("/order/payMoney",row).then((res)=>{
              if(res.data.success){
                document.write(res.data.result);
                this.$router.push("/orderList")
              }
            })
        }
      },
      mounted() {
        this.searchList();
        this.searchUser();
      },
      filters:{
        staFit:function (val) {
          if(val==0){
            return "待支付"
          }
          if(val==1){
            return "支付完成"
          }
        },
      }
    }
</script>

<style scoped>

</style>
